package com.wetao.module_user.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.appcompat.widget.AppCompatTextView;

import com.wetao.lib_common.base.BaseLazyFragment;
import com.wetao.lib_common.utils.BaseEvent;
import com.wetao.module_user.R;
import com.wetao.module_user.contract.UserPenFragmentCon;
import com.wetao.module_user.presenter.UserPenFragmentPre;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class UserPenFragment extends BaseLazyFragment<UserPenFragmentCon.View, UserPenFragmentPre> implements
        UserPenFragmentCon.View {


    public static UserPenFragment newInstance(String penMac) {
        Bundle args = new Bundle();
        args.putString("penMac", penMac);

        UserPenFragment fragment = new UserPenFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.user_fragment_pen;
    }

    @Override
    public UserPenFragmentPre createPresenter() {
        return new UserPenFragmentPre(mContext);
    }

    @Override
    public UserPenFragmentCon.View createView() {
        return this;
    }

    @Override
    public void init(View rootView) {
        AppCompatTextView tvMac = rootView.findViewById(R.id.tv_pen_mac);

        Bundle bundle = null;
        if ((bundle = getArguments()) != null) {
            String penMac = bundle.getString("penMac");
            if(!TextUtils.isEmpty(penMac)) {
                tvMac.setText(String.format(getContext().getResources().getString(R.string.user_pen_mac), penMac));
            }
            int classId = bundle.getInt("classId");
        }

    }

    @Override
    public void onFragmentFirst() {
        super.onFragmentFirst();
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Override
    public void onFragmentInVisible() {
        super.onFragmentInVisible();
    }

    @Override
    public void onFragmentVisble() {
        super.onFragmentVisble();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN) //在ui线程执行
    public void onEventReceived(BaseEvent event) {
        if (event.getCode() == 1) {//退出登录  刷新列表

        }
    }
}
